"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const maishu_chitu_admin_1 = require("maishu-chitu-admin");
require("./database");
const common_1 = require("./common");
const path = require("path");
const website_config_1 = require("./website-config");
const errors_1 = require("./errors");
const maishu_node_auth_1 = require("maishu-node-auth");
var website_config_2 = require("./website-config");
exports.menuItemIds = website_config_2.menuItemIds;
async function start(settings) {
    if (!settings)
        throw errors_1.errors.argumentNull("settings");
    Object.assign(common_1.settings, settings);
    await maishu_node_auth_1.createDatabaseIfNotExists(settings.db);
    let sourcePath = path.join(__dirname, "./");
    let componentInfos = common_1.getClientComponentInfos(sourcePath);
    let serverContextData = { gateway: settings.gateway };
    maishu_chitu_admin_1.start({
        port: settings.port,
        rootDirectory: __dirname,
        virtualPaths: Object.assign(settings.virtualPaths || {}, {
            "mobile/json.js": path.join(__dirname, 'static/lib/requirejs-plugins/src/json.js'),
            "mobile/text.js": path.join(__dirname, 'static/lib/requirejs-plugins/lib/text.js'),
        }),
        sourceDirectory: sourcePath,
        proxy: {
            "^/Images/Editor/(\\S+)": "http://web.alinq.cn/store2/Images/Editor/$1"
        },
        actionFilters: [
            (req, res, context) => {
                context.componentInfos = componentInfos;
                return null;
            }
        ],
        station: {
            gateway: settings.gateway,
            path: website_config_1.stationPath,
            permissions: website_config_1.permissions
        },
        logLevel: "all",
        serverContextData,
    });
}
exports.start = start;
